package com.edu.exam.enums.examination;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 考试会话状态枚举
 * 管理考试会话的完整生命周期状态
 *
 * @author System
 * @version 1.0.0
 */
public enum ExamSessionState implements BaseEnum {

    CREATED("CREATED", "已创建", 1),
    PENDING_AUTH("PENDING_AUTH", "待认证", 2),
    AUTHENTICATING("AUTHENTICATING", "认证中", 3),
    AUTHENTICATED("AUTHENTICATED", "已认证", 4),
    READY("READY", "就绪", 5),
    IN_PROGRESS("IN_PROGRESS", "进行中", 6),
    PAUSED("PAUSED", "暂停", 7),
    SUSPENDED("SUSPENDED", "挂起", 8),
    COMPLETED("COMPLETED", "已完成", 9),
    ABNORMAL("ABNORMAL", "异常", 10),
    TERMINATED("TERMINATED", "终止", 11),
    EXPIRED("EXPIRED", "过期", 12);

    private final String code;
    private final String description;
    private final int order;

    ExamSessionState(String code, String description, int order) {
        this.code = code;
        this.description = description;
        this.order = order;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public int getOrder() {
        return order;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static ExamSessionState fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Exam session state code cannot be null or empty");
        }

        for (ExamSessionState state : values()) {
            if (state.getCode().equals(code)) {
                return state;
            }
        }
        throw new IllegalArgumentException("Unknown exam session state code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static ExamSessionState fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Exam session state description cannot be null or empty");
        }

        for (ExamSessionState state : values()) {
            if (state.getDescription().equals(description)) {
                return state;
            }
        }
        throw new IllegalArgumentException("Unknown exam session state description: " + description);
    }
}